**Housekeeping
clear all
cap log close
log using ${rep_root}/logs/blm_trends.log, text replace
set more off

insheet using ${rep_root}/data/blm_data.csv
rename v1 incident
gen count = 1
replace subject = subinstr(subject, "Subject(s): ", "", .)
split subject, parse(", ") gen(sub)
 
gen year = substr(date, -5, 5)
destring year, replace force
 
split date, p(", ") 
split date2, p(" ")


rename date21 month
replace month = lower(month)


gen month1 = 1 if month == "january"
replace month1 = 2 if month == "february"
replace month1 = 3 if month == "march"
replace month1 = 4 if month == "april"
replace month1 = 5 if month == "may"
replace month1 = 6 if month == "june"
replace month1 = 7 if month == "july"
replace month1 = 8 if month == "august"
replace month1 = 9 if month == "september"
replace month1 = 10 if month == "october"
replace month1 = 11 if month == "november"
replace month1 = 12 if month == "december"
 
gen yearmo = ym(year, month1)
format %tm yearmo

replace participant = subinstr(participant, "Participant(s): ", "", .) 
replace participant = subinstr(participant, " demonstrators", "", .)
replace participant = subinstr(participant, ",", "", .)  
gen parttemp = regexs( 1 ) if regexm( participant, "([0-9]+).*" )

*placevar parttemp, after(participant)
replace parttemp = "50" if strpos(participant, "Dozens")
replace parttemp = "500" if strpos(participant, "Hundreds")
replace parttemp = "5000" if strpos(participant, "Thousands")
 
 
destring parttemp, replace
sum parttemp, d
 




 
gen state = substr(plocation, -2,2)
gen agency = substr(plocation, 1, strpos(plocation, ", ")-1)
sort state
drop if state>"WV"

split plocation, p(", ")
replace agency = plocation2  if plocation3 != ""
drop if parttemp<5
drop if strpos(description, "NFL")| strpos(description, "knelt")
drop if strpos(subject, "Trump")
drop if strpos(subject, "LGBT")
drop if strpos(subject, "Campus Racism") 
drop if strpos(subject, "National Anthem") 
drop if strpos(subject, "Nationalism") 
drop if strpos(subject, "Gentrification") 
drop if strpos(subject, "Clinton") 
drop if strpos(subject, "Education") 
drop if strpos(subject, "Confederate")
drop if strpos(subject, "Confederacy")
drop if strpos(subject, "Campus") 
drop if strpos(subject, "Immigrant Rights") 
drop if strpos(subject, "NFL") 
drop if strpos(subject, "Prison")
drop if strpos(subject, "Supremacy") 
drop if strpos(subject, "WNBA") 
drop if strpos(subject, "Rikers") 
drop if strpos(subject, "Martin Luther King") 
drop if strpos(subject, "Hate Speech") 
drop if strpos(subject, "Cemetary") 
drop if strpos(subject, "Black History Month") 
drop if strpos(subject, "Bernie Sanders") 
drop if strpos(subject, "Anti-Black-Lives") 
drop if strpos(subject, "2016 Presidential") 
drop if agency == "Dallas and Arlington"

tab description if subject == "General" | subject == "Others"
drop if strpos(description, "LGBT")
drop if strpos(description, "Confederate")
drop if strpos(description, "Confederacy")

destring date22, replace
gen obs =1
 
 
keep if strpos(plocation , "Chicago"  ) 
sort yearmo


collapse (sum) obs, by(yearmo)

outsheet using ${rep_root}/data/blm_data_cleaned.csv, replace comma


twoway line obs yearmo, xtitle("Time") ytitle("Number of Protests in a Month in Chicago") tline(2015m11)  

 
